package com.heisnenhub.common.module.utils;

import com.heisnenhub.common.module.exception.RRException;
import com.heisnenhub.common.module.inter.ThrowExceptionFunction;

import java.util.function.Consumer;

public class ThrowExceptionUtils {

    static Consumer<String> action = (str) ->  {throw new RRException(str) ;}  ;

   public static ThrowExceptionUtils orThrow(boolean b ,String str){
        if(b) action.accept(str);
        return new ThrowExceptionUtils();
    }



    /**
     *  如果参数为true抛出异常
     *
     * @param b
     * @return com.example.demo.func.ThrowExceptionFunction
     **/
    public static ThrowExceptionFunction isTure(boolean b){

        return (errorMessage) -> {
            if (b){
                throw new RRException(errorMessage);
            }
        };
    }

    public   ThrowExceptionUtils or(boolean b ,String str){
        if(b) action.accept(str);
        return new ThrowExceptionUtils() ;
    }

    public static void main(String[] args) {
        ThrowExceptionUtils.orThrow(false  , "11111").or(true ,"2222222222222");
    }
}
